package com.pm.service.file.impl;

import com.pm.entity.po.file.DailyFileLib;
import com.pm.entity.po.file.DailyFileType;
import com.pm.entity.vo.dept.DailyFileTypeVo;
import com.pm.mapper.file.DailyFileLibMapper;
import com.pm.mapper.file.DailyFileTypeMapper;
import com.pm.service.file.DailyFileTypeService;
import com.pm.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DailyFileTypeServiceImpl extends BaseServiceImpl<DailyFileType> implements DailyFileTypeService {
    @Autowired
    DailyFileTypeMapper dailyFileTypeMapper;
    @Autowired
    DailyFileLibMapper dailyFileLibMapper;

    @Resource
    private void setBaseMapper(DailyFileTypeMapper dailyFileTypeMapper) {
        super.setBaseMapper(dailyFileTypeMapper);
    }

    @Override
    public DailyFileTypeVo getListDailyFileType(DailyFileType dailyFileType) {
        DailyFileTypeVo dailyFileTypeVos = new DailyFileTypeVo();
        if (dailyFileType.getParentId()==null){
            List<DailyFileType> dailyFileTypesOne = null;
            List<DailyFileLib> dailyFileLibOne =  null;
            // 文件夹
            dailyFileTypesOne =dailyFileTypeMapper.getListType(dailyFileType);
            dailyFileLibOne = dailyFileLibMapper.getListDailyFileLib(null);
            dailyFileTypeVos.setDailyFileTypes(dailyFileTypesOne);
            dailyFileTypeVos.setDailyFileLibs(dailyFileLibOne);
            dailyFileTypeVos.setFatherId(null);
            return dailyFileTypeVos;
        }else{
            List<DailyFileType> dailyFileTypesOne = null;
            // 文件夹
            dailyFileTypesOne =   dailyFileTypeMapper.getListDailyFileType(dailyFileType);
            List<DailyFileLib> dailyFileLibs = null;
            // 文件
            dailyFileLibs = dailyFileLibMapper.getListDailyFileLib(dailyFileType.getParentId());
            dailyFileTypeVos.setDailyFileTypes(dailyFileTypesOne);
            dailyFileTypeVos.setDailyFileLibs(dailyFileLibs);
            dailyFileTypeVos.setFatherId(dailyFileTypeMapper.getFatherId(dailyFileType.getParentId()));
            dailyFileTypeVos.setParentIdNew(dailyFileTypeMapper.getParentIdNew(dailyFileType.getParentId()));
            return dailyFileTypeVos;
        }

    }
}
